﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace MS.Utility.Common
{
    public class CommonHelper
    {
        /// <summary>
        /// 获得当前页面客户端的IP
        /// </summary>
        /// <returns>当前页面客户端的IP</returns>
        public static string GetIP()
        {
            string result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            if (string.IsNullOrEmpty(result))
                result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (string.IsNullOrEmpty(result))
                result = HttpContext.Current.Request.UserHostAddress;

            if (string.IsNullOrEmpty(result) || !Utils.IsIP(result))
                return "127.0.0.1";

            return result;
        }

        /// <summary>
        /// 在各系统Global里面是否记录日志
        /// </summary>
        /// <returns></returns>
        public static bool IsGlobalLog()
        {
            if (UserHelper.GetRequestUrl().ToLower().Contains("/images/") || UserHelper.GetRequestUrl().ToLower().Contains("/content/") || UserHelper.GetRequestUrl().ToLower().Contains("/scripts/"))
            {
                return false;
            }
            return true;
        }
    }
}
